﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufBase.h"
#include "GnufToolButton.h"

namespace gnuf {

    /*
    The behavior of ListButton is almost the same as ComboBoxButton. While the difference is that,
    the ListButton need to intrinsically support a SelectAll button composited within the dropDown board,
    so that all of the items will be selected when click above the SelectAll button. Meanwhile, the listButton
    shall display the captions of selected items.
    */
    class DropDownBoard;
    class CheckButton;
    class GNUF_BASE_EXPORT CheckListButton final
        : public ToolButton
    {
    public:
        static const EItemType Type;

        explicit CheckListButton(Item*);
        virtual ~CheckListButton() {}

        void setItemStatus(int, bool, bool fromOutside = true);
        void setItemEnabled(int, bool);
        void addItem(const Info&, bool);

        void enableSelectAll(bool is, const std::wstring& caption);
        void enableMultiSelect(bool is) { m_multiSelect = is; }

        const std::vector<bool> getCurrentStatus() const { return m_status; }
        virtual void onDropDownBoardClosed(DropDownBoard*);

    protected:
        virtual void onDropDownBoardItemClicked(Item*) override;

    private:
        void refreshCaption();
        bool m_enableSelectAll;
        bool m_multiSelect;
        std::vector<bool> m_status;
        CheckButton* m_selectAllBtn;
        std::wstring m_selectAllDisplayName;
    };
}
